const { app, Tray, Menu } = require("electron");
const path = require("path");
const windowManager = require("./windowMamager.cjs");

function initTray() {
  let tray = new Tray(path.join(__dirname, "assets/icon-128.png"));
  const contextMenu = Menu.buildFromTemplate([
    {
      label: "显示",
      click: function () {
        if (windowManager.has("searchWin")) {
          windowManager.get("searchWin").show();
          windowManager.get('searchWin').setAlwaysOnTop(true);
        }
      },
    },
    {
      label: "隐藏",
      click: function () {
        if (windowManager.has("searchWin")) {
          windowManager.get("searchWin").hide();
          windowManager.get('searchWin').setAlwaysOnTop(false);
        }
      },
    },
    {
      label: "关闭",
      click: function () {
        app.quit();
      },
    },
  ]);
  tray.on("double-click", function () {
    if (windowManager.has("searchWin")) {
      windowManager.get("searchWin").show();
      windowManager.get('searchWin').setAlwaysOnTop(true);
    }
  });
  // 设置鼠标悬停时的提示文本
  tray.setToolTip("AI 助手");
  tray.setContextMenu(contextMenu);
  return tray;
}
module.exports = {
  initTray,
};
